package lock;

import java.util.concurrent.TimeUnit;

// static synchronized
public class Demo4 {
    public static void main(String[] args) {
        Phone4 phone = new Phone4();

        new Thread(()->{
            phone.listenMusic();
        },"A").start();

        try {
            //线程休息1毫秒
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            phone.playGame();
        },"B").start();
    }
}
class Phone4{
    public static synchronized void listenMusic(){
        try {
            //线程休息1毫秒
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("听音乐！");
    }

    public static synchronized void playGame(){
        System.out.println("玩游戏！");
    }
}